package com.bnz.manager.service.impl;

import com.bnz.common.PageUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.bnz.common.Query;

import com.bnz.manager.dao.ContentDao;
import com.bnz.manager.entity.ContentEntity;
import com.bnz.manager.service.ContentService;


@Service("contentService")
public class ContentServiceImpl extends ServiceImpl<ContentDao, ContentEntity> implements ContentService {
    @Autowired
    private StringRedisTemplate redisTemplate;
    @Override
    public PageUtils queryPage(Map<String, Object> params) {
        IPage<ContentEntity> page = this.page(
                new Query<ContentEntity>().getPage(params),
                new QueryWrapper<ContentEntity>()
        );

        return new PageUtils(page);
    }

    // 增加
    @Override
    public void insert(ContentEntity content) {
        // 1. 清除缓存
        redisTemplate.delete("contentList");
        this.save(content);
    }

    // 修改
    @Override
    public void updateContent(ContentEntity content) {
        // 1. 清除缓存
        redisTemplate.delete("contentList");
        this.updateById(content);
    }

    // 删除
    @Override
    public void deleteByIds(List<String> asList) {
        // 1. 清除缓存
        redisTemplate.delete("contentList");
        this.removeByIds(asList);
    }

}